<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<c:set var="ctx" value=" ${pageContext.request.contextPath}" />
<html>
<head>
<title>审计明细管理</title>
<script src="${ctx}/static/selectWin/employeeSelector.js?version=${applicationScope.jsVersion }" type="text/javascript"></script>
<script src="${ctx}/static/selectWin/orgSelector.js?version=${applicationScope.jsVersion }" type="text/javascript"></script>
<script type="text/javascript">

	var $grid;
	var grid;
	$(function() {
		$grid = $("#grid").datagrid($.extend(datagridOption, {
			url : "${ctx}/fnd/auditProDtl/dataGrid?auditId=${auditPro.id}&businessKey=${param.businessKey}",
			//fitColumns : true,
			nowrap:false,
			frozenColumns : [ [] ],
			columns : [ [ {
				field : 'ck',
				checkbox : true
			} ,{
				field : 'auditPro.auditName',
				title : '审计监察法务项目',
				width :　220,
				sortable : true
			}, {
				field : 'wfl',
				title : '审批信息',
				width : 65,
				sortable : true,
				formatter : fmt_wfl_view
			} , {
				field : 'confirmFlag',
				title : '审批状态',
				width : 65,
				sortable : true,
				formatter : function(value, row, index) {
					if (value == "0") {
						return "<span>起草<span>";
					} else if (value == "2") {
						return "<span style='color:orange'>审批中<span>";
					} else if (value == "1") {
						return "<span style='color:green'>已通过<span>";
					} else if (value == "-1") {
						return "<span style='color:red'>已取消<span>";
					}
				}
			},{
				field : 'org.orgName',
				title : '部门名称',
				width :　140,
				sortable : true
			},{
				field : 'employee.trueName',
				title : '责任人 ',
				width :　55,
				sortable : true
			},{
				field : 'superintendent.trueName',
				title : '内控监督人',
				width :　90,
				sortable : true
			},{
				field : 'auditEvaluation',
				title : '审计监察法务评价',
				width :　400,
				sortable : true,
				formatter: function (value) {
					if(value)
		               return "<span title='" + value + "'>" + value + "</span>";
		        }
			},{
				field : 'auditEvaluationNo',
				title : '评价代码',
				width :　120,
				sortable : true
			} ,{
				field : 'auditFinding',
				title : '发现问题',
				width :　400,
				sortable : true,
				formatter: function (value) {
					if(value)
			               return "<span title='" + value + "'>" + value + "</span>";
		        }
			} ,{
				field : 'auditFindingNo',
				title : '发现问题代码',
				width :　120,
				sortable : true
			},{
				field : 'auditSuggestion',
				title : '建议',
				width :　400,
				sortable : true,
				formatter: function (value) {
					if(value)
			               return "<span title='" + value + "'>" + value + "</span>";
		        }
			} ,{
				field : 'auditSuggestionNo',
				title : '建议代码',
				width :　120,
				sortable : true
			}  ,{
				field : 'zgPlanSubTime',
				title : '整改计划最迟提交时间 ',
				width :　150,
				sortable : true
			},{
				field : 'zgPlanSubSjTime',
				title : '整改计划实际提交时间 ',
				width :　150,
				sortable : true
			},{
				field : 'zgResultSubTime',
				title : '整改结果最迟提交时间（整改计划完成时间） ',
				width :　300,
				sortable : true
			},{
				field : 'zgResultSubSjTime',
				title : '整改结果实际提交时间 ',
				width :　150,
				sortable : true
			}, {
				field : 'auditPro.attachmentMaster',
				title : '审计监察法务项目附件',
				sortable : true,
				formatter : function(value, row, index) {
					if(row.auditPro.attachCnt==0){
						return "<button id=\"attach\" type=\"button\" class=\"btn btn-default\" onclick=\"fn_attachClick('"+value.id+"',"+row.auditPro.detailsApprCnt+")\"><span class=\"glyphicon glyphicon-pencil\"></span> 附件</button>";
					}else{
						return "<button id=\"attach\" type=\"button\" class=\"btn btn-primary\" onclick=\"fn_attachClick('"+value.id+"',"+row.auditPro.detailsApprCnt+")\"><span class=\"glyphicon glyphicon-pencil\"></span> 附件</button>";
					}
				}
			}
      ] ],
			onDblClickRow : function(index, rowData) {
				$.isFunction(fn_edit) && fn_edit.call(this, rowData);
			} 
		}));
		
		$orgSelector = $("#org").comboselector(orgSelectOpts);
		$employeeSelector = $("#employee").comboselector(employeeSelectOpts);
		$superintendentSelector = $("#superintendent").comboselector($.extend(employeeSelectOpts, {			
			url : kl.ctx + "/fnd/employee/dataGrid?search_EQ_enable=1&search_IN_org.orgNo=BSSGFY00,BSSGFE00",
		}));		


		
		$grid.datagrid('enableFilter', [ buildDGFilterYesOrNoFieldOptions($grid, 'enable') ]);
		$grid.datagrid('enableFilter', [ {
			field : 'auditPro',
			searchField : 'auditPro.auditName'
		}, {
			field : 'employee',
			searchField : 'employee.trueName'
		},   {
			field : 'org',
			searchField : 'org.orgName'
		}, {
			field : 'confirmFlag',
			type : 'combobox',
			options : {
				panelHeight : 'auto',
				data : [ {
					value : ' ',
					text : '全部',
					selected : true
				},{
					value : '0',
					text : '起草'
				}, {
					value : '2',
					text : '审批中'
				}, {
					value : '1',
					text : '审批通过'
				}, {
					value : '-1',
					text : '已取消'
				}  ],
				onChange : function(value) {
					if (value == '') {
						$grid.datagrid('removeFilterRule', 'confirmFlag');
					} else {
						$grid.datagrid('addFilterRule', {
							field : 'confirmFlag',
							op : 'EQ',
							value : value
						});
					}
					$grid.datagrid('doFilter');
				}
			}
		}]);
		
		 
		
	 $("#add").click(function() {
			$("#fm").form("clear");
			$('#fm').form('load',{
			 	auditPro :'${auditPro.id}',
			 	confirmFlag : 0
			});
	     	$("#dlg-btn").show();
			$("#dlg").dialog("open").dialog("setTitle", "新增审计监察法务明细");
		});
		$("#edit").click(function() {
			var rowData = $grid.datagrid("getSelected");
			if (!rowData) {
				showInfo("您未选中行，无法编辑 / 查看");
			} else {
				fn_edit(rowData);
			}
		});
		$("#delete").click(function() {
			multiDeleteDataGrid($grid, "${ctx}/fnd/auditProDtl/multiDelete");
		});
		 
		//excel导入
		$("#excelImport").click(function() {
			$.easyui.importor.showImportor({
				importNo : "auditProDtl",
				onExportSuccess : function(file, data) {
					$grid.datagrid('load');
				}
			});
		});
		
		 $("#excelExport").click(function() {//auditId=${auditPro.id}
					var url = "${ctx}/fnd/auditProDtl/excelExport?auditProId=${auditPro.id}&" + $.param($grid.datagrid('options').queryParams);
					if ($grid.datagrid("options").filterRules) {
						url += "&filterRules=" + JSON.stringify($grid.datagrid("options").filterRules);
					}
					window.parent.location.href = url;
				}); 

$("#apply").click(function() {
	 
	//自行添加启动流程前的判断逻辑以及启动流程过程中不能修改单据的逻辑
	var rowData = $grid.datagrid("getSelected");
	if (!rowData) {
		showInfo("您未选中行，无法发起流程");
	} else {
		if(!rowData.processInstanceId&&rowData.confirmFlag!=1){
			if(rowData.org&&rowData.org.id){				
				showConfirm("您确定要启动审批流程吗？<br>启动审批后将<strong>不允许修改和删除!</strong>!", function() {
					wflStart("${ctx}/fnd/auditProDtl/apply/" + $grid.datagrid("getSelected").id, function() {
						$grid.datagrid("reload");
					});
				});
			}else{
				showInfo("请选择责任部门！")
			}
		}else{
			showInfo("该行已在审批中或审批完毕，不能再次发起审批！")
		}
	}
});


	});
	 function fn_edit(rowData) {
			if (rowData.confirmFlag == 0) {
				$("#dlg-btn").show();
				$("#dlg").dialog("open").dialog("setTitle", "编辑审计监察法务明细");
			} else {
				$("#dlg-btn").hide();
				$("#dlg").dialog("open").dialog("setTitle", "查看审计监察法务明细");
			}
			$("#fm").form("clear");
			$("#fm").form("load", $.extend(rowData, {			
				"auditPro" :rowData.auditPro.id
			}));
			 
			  rowData.employee
					&& $("#employee").comboselector("setValue",
							rowData.employee.id).comboselector("setText",
							rowData.employee.trueName); 
			  rowData.org
				&& $("#org").comboselector("setValue",
						rowData.org.id).comboselector("setText",
						rowData.org.orgName); 
			  
			  rowData.superintendent
				&& $("#superintendent").comboselector("setValue",
						rowData.superintendent.id).comboselector("setText",
						rowData.superintendent.trueName); 
	}
	 
	 
	 
	//-----------------------------附件-----------------------------------------------//		
		function fn_attachClick(id,confirmFlag){
		  
			grid&&grid.datagrid('loadData',{total:0,rows:[]});
			grid = $("#grid_attach").datagrid({
				title : "附件",
				fitColumns : true,
				method : "get",
				singleSelect : true,
				pagination : true,
				url : "${ctx}/basic/attachment/dataGrid/"+id
			});
			
		 
				$("#dlg_attach").dialog("open").dialog("setTitle", "查看附件");
				$('#uploader').hide();
				
				
				
			 
		}
	
	
	
		function fn_attach_formatter(value, row, index) {
			var rowData = $grid.datagrid('getSelected');
			var button = "";
			//if (rowData.confirmFlag == 0) {
			if(rowData.auditPro.detailsApprCnt>0){
				button = fmt_attach(value, row, index);
			} else {
				button = fmt_attachView(value, row, index);
			}
			return button;
		}
	
</script>
</head>



<body>
	<div data-options="region:'center',fit:true,border:false">
		<table id="grid">
		</table>
	</div>
	<div id="tt" class="row">
		<div class="col-md-12">
		
		<c:if test="${empty param.businessKey}">
			<button id="return" type="button" class="btn btn-success" onclick="go('${ctx}/fnd/auditPro/${type}')">
				<span class="ace-icon glyphicon glyphicon-arrow-left"></span> 返回上一层
			</button>
			<shiro:hasPermission name="auditPro:update">
				<button id="add" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-plus"></span> 新增
				</button>
			</shiro:hasPermission>
		</c:if>
				<button id="edit" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-pencil"></span> 编辑 / 查看
				</button>
		<c:if test="${empty param.businessKey}">
			<shiro:hasPermission name="auditProDtl:update">
				<button id="apply" type="button" class="btn btn-success">
						<span class="glyphicon glyphicon-send"></span> 发起审批
				</button>
			</shiro:hasPermission>
			<shiro:hasPermission name="auditProDtl:delete">
				<button id="delete" type="button" class="btn btn-danger">
					<span class="glyphicon glyphicon-minus"></span> 删除
				</button>
			</shiro:hasPermission>
			<shiro:hasPermission name="auditProDtl:import">
				<button id="excelImport" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-save"></span> Excel导入
				</button>
				
			</shiro:hasPermission>
			<shiro:hasPermission name="auditProDtl:export">
				<button id="excelExport" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-open"></span> Excel导出
				</button>
			</shiro:hasPermission>
			</c:if>
			<span style="float:right;padding:8px 0 0 0;color:red;">双击行或点击“编辑 / 查看”按钮，可打开窗口查看详细数据</span>
		</div>
	</div>

		<div id="dlg" class="easyui-dialog" style="width: 1060px; height:500px; padding: 10px 20px"
			data-options="resizable:true,modal:true, buttons:'#dlg-btn',closed:true">
			<form id="fm" method="post">
		<input type="hidden" name="id" />   <input type="hidden" name="auditPro"  name="auditPro" />   
				<table id="tbl">
				  
				   
				    <tr>
				        <td colspan="2"><label>审计监察法务评价：</label></td>
				       <td colspan="2"><label>审计监察法务发现问题：</label></td>
					    <td colspan="2"><label>审计监察法务建议：</label></td>
					</tr>
					  <tr>
					     <td  colspan="2"><input name="auditEvaluation" class="easyui-textbox" data-options="multiline:true, width:300, height:240"></td>
					     <td colspan="2"><input name="auditFinding" class="easyui-textbox" data-options="multiline:true,  width:315, height:240,required: true"></td>
					     <td colspan="2"><input name="auditSuggestion" class="easyui-textbox" data-options="multiline:true, width:320, height:240, required: true"></td>
					 
					  </tr>
					 <tr>
				        <td><label>评价代码:</label></td>
						<td ><input name="auditEvaluationNo" class="easyui-validatebox" data-options="required: true"></td>
						<td><label>发现问题代码:</label></td>
						<td ><input name="auditFindingNo" class="easyui-validatebox" data-options="required: true"></td>
					    <td><label>建议代码:</label></td>
						<td ><input name="auditSuggestionNo" class="easyui-validatebox" data-options="required: true"></td>
					
				   </tr>
					<!--  <tr>
					     <td></td> 
					 	 <td></td>			
					  <td><label>发现问题所属评价代码:</label></td>
						<td ><input name="auditFindingEva" class="easyui-validatebox" data-options="required: true"></td>
						 <td><label>建议所属发现问题代码:</label></td>
						<td><input name="auditSuggestionFin" class="easyui-validatebox" data-options="required: true"></td>
					 </tr> -->
					 <tr>
					     <td>部门名称：</td> 
					 	 <td><input id="org" name="org" class="easyui-validatebox" data-options=""></td>
					 	 <td>内控监督人：</td> 
					 	 <td><input id="superintendent" name="superintendent" class="easyui-validatebox" data-options=""></td>
					 	 <td>整改计划提交时间：</td> 
					 	 <td><input id="zgPlanSubTime" name="zgPlanSubTime" class="easyui-datebox" data-options="disabled:true"></td>
					 </tr>
				</table>
			</form>
			<div id="dlg-btn">
				<button id="add" type="button" class="btn btn-primary" onclick="formSave('#fm', '#grid', '#dlg', '${ctx}/fnd/auditProDtl/update');">
					<span class="glyphicon glyphicon-ok"></span> 保存
				</button>
				<button id="edit" type="button" class="btn btn-primary" onclick="$('#dlg').dialog('close');">
					<span class="glyphicon glyphicon-remove"></span> 取消
				</button>
			</div>
		</div>

	
	
		<div id="dlg_attach" class="easyui-dialog"
			style=" padding: 10px 20px"
			data-options="resizable:true,modal:true,closed:true,fit:true">
			<div  class="easyui-layout" data-options="fit:true">   
				<div data-options="region:'center',border:false">
					<table id="grid_attach" data-options="fit:true">
						<thead>
							<tr>
								<th field="id" hidden="true"></th>
								<th field="fileName" width="160">文件名称</th>
								<th field="fileSize" width="60">大小</th>
								<th field="uploadTime" width="60">上传时间</th>
								<th field="operate" width="60" data-options="formatter:fn_attach_formatter"  >操作</th>
							</tr>
						</thead>
					</table>
				</div>
				<div data-options="region:'south'" style="height:150px">
					<div id="uploader" class="wu-example">
					    <div class="btns">
					        <div id="picker">选择文件</div>
					    </div>
					     <!--用来存放文件信息-->
					    <div id="thelist" class="uploader-list"></div>
					</div>
				</div>
			</div>
		</div>
 

</body>
 
</html>
